limsBatch.batchSampleProductChoosePage = {

    getGridParam: function () {
        var _this = this, columns = limsBatch.batchSampleProductChooseListColumns();
        _this.param.single ? columns.unshift({
            radio: true
        }) : columns.unshift({
            checkbox: true
        });
        return {
            type: 'grid',
            id: 'lims-batch-sample-product-choose-list-grid',
            url: limsBatch.batchSampleProductUrl + '/batch-sample-products',
            requestData: _this.param,
            page: true,
            filterOpen: true,
            columns: columns,
            toolbar: [{
                type: 'button',
                text: 'GIKAM.BUTTON.CONFIRM',
                icon: 'select',
                onClick: function () {
                    Gikam.getLastModal().close(Gikam.getComp('lims-batch-sample-product-choose-list-grid').getSelections());
                }
            }, {
                type: 'button',
                text: 'GIKAM.TITLE.CHOOSE.SEARCH',
                icon: 'select',
                onClick: function () {
                    Gikam.create('modal', {
                        title: 'GIKAM.TITLE.CHOOSE.SEARCH',
                        height: 400,
                        width: 400,
                        url: limsBatch.sampleUrl + '/page/sample-select' + Gikam.param({
                            type: 'sample'
                        }),
                        onAfterClose: function (data) {
                            if (Gikam.isEmpty(data)) {
                                return;
                            }
                            let items = data.sampleCode.replace(/[(\r\n)|(\ +)|(，)|(；)|(;)]/g, ',');
                            let requestParam = JSON.parse(JSON.stringify(_this.param))
                            requestParam.sampleCode_IN = items
                            Gikam.post(limsBatch.batchSampleProductUrl + '/batch-sample-products', Gikam.getJsonWrapper({
                                f: requestParam
                            })).done(function (data) {
                                Gikam.getComp('lims-batch-sample-product-choose-list-grid').loadData(data.rows);
                            })
                        }
                    })
                }
            }]
        }
    },

    create: function () {
        var _this = this;
        Gikam.create('layout', {
            id: 'lims-sample-choose-list-layout',
            renderTo: Gikam.getLastModal().window.$dom,
            center: {
                items: [this.getGridParam()]
            }
        });
    },

    init: function (param) {
        this.param = param;
        this.create();
    }
};
